In [2]:
import pandas as pd
import numpy as np
from sklearn import preprocessing, cross_validation
from sklearn.linear_model import LinearRegression
import warnings
import matplotlib.pyplot as plt
from matplotlib import style
df = pd.read_csv('Height.csv')
In [76]:
df
Out[76]:
In [77]:
df = df[['Height(Inches)','Weight(Pounds)']]
In [78]:
df
Out[78]:
In [116]:
X = np.array(df['Height(Inches)'])
y = np.array(df['Weight(Pounds)'])
#Shaping to tell that only one feature is there
X = X.reshape(-1, 1)
In [117]:
X_train, X_test, y_train, y_test = cross_validation.train_test_split(X, y, test_size = 0.4)
In [87]:
cf = LinearRegression()
In [120]:
cf.fit(X_train, y_train)
accuracy = cf.score(X_test, y_test)
print('Accuracy: ',int(accuracy*100),'%')
In [131]:
plt.scatter(X, y, color = 'black')
plt.plot(X, cf.predict(X), color = 'red', linewidth=1)
plt.xlabel('Height(Inches)', color = 'blue')
plt.ylabel('Weight(Pounds)', color = 'blue')
plt.show()